// token 在Vuex中初始化
import { loginApi } from "@/api/user.js"

const state = {
    token:null,
    userInfo:{}
}
const mutations = {
    setToken(state, token) {
        state.token = token
    },
    removeToken(state) {
        state.token = null
    },
    setUserInfo(state, userInfo) {
        state.setUserInfo = userInfo
    }, 
    removeInfo(state) {
        state.userInfo = {}
    }, 
}
const actions ={
   async loginAction(context,data){
        // 调用登陆接口
      try{
        const res =  await loginApi(data)
      console.log(res);
    //   console.log(context);
    context.commit('setToken', res.token)
      }catch(err){
        throw new Error()
      }
    }
}

// 抛出
export default {
    namespaced: true,
    state,
    mutations,
    actions
}
